﻿using PARK.Common.Const;
using SqlSugar;
using System;
using Yitter.IdGenerator;

namespace PARK.Accessctl.Entitys
{
    /// <summary>
    /// 门禁权限
    /// </summary>
    [SugarTable("access_ctlauth")]
    [Tenant(ClaimConst.TENANT_ID)]
    public class AccessCtlauthEntity
    {
        /// <summary>
        /// 主键Id
        /// </summary>
        [SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
        public string Id { get; set; }
        
        /// <summary>
        /// 控制器Id
        /// </summary>
        [SugarColumn(ColumnName = "ctlId")]        
        public string CtlId { get; set; }
        
        /// <summary>
        /// 控制器SN
        /// </summary>
        [SugarColumn(ColumnName = "ctlSN")]        
        public string CtlSn { get; set; }
        /// <summary>
        /// 控制器ctlName
        /// </summary>
        [SugarColumn(ColumnName = "ctlName")]
        public string ctlName { get; set; }
        /// <summary>
        /// 控制器门Id
        /// </summary>
        [SugarColumn(ColumnName = "doorId")]        
        public string DoorId { get; set; }
        
        /// <summary>
        /// 门号  1,2,3,4
        /// </summary>
        [SugarColumn(ColumnName = "doorNo")]        
        public string DoorNo { get; set; }
        
        /// <summary>
        /// 门名称
        /// </summary>
        [SugarColumn(ColumnName = "doorName")]        
        public string DoorName { get; set; }
        
        /// <summary>
        /// 权限用户
        /// </summary>
        [SugarColumn(ColumnName = "EmployeeId")]        
        public string EmployeeId { get; set; }
        
        /// <summary>
        /// 工号
        /// </summary>
        [SugarColumn(ColumnName = "JobNo")]        
        public string JobNo { get; set; }
        
        /// <summary>
        /// 姓名
        /// </summary>
        [SugarColumn(ColumnName = "ReallName")]        
        public string ReallName { get; set; }
        
        /// <summary>
        /// 部门Id
        /// </summary>
        [SugarColumn(ColumnName = "DepartId")]        
        public string DepartId { get; set; }
        
        /// <summary>
        /// 部门
        /// </summary>
        [SugarColumn(ColumnName = "DepartName")]        
        public string DepartName { get; set; }
        
        /// <summary>
        /// 卡号
        /// </summary>
        [SugarColumn(ColumnName = "CardNo")]        
        public string CardNo { get; set; }
        
        /// <summary>
        /// 有效时长，开始
        /// </summary>
        [SugarColumn(ColumnName = "StartTime")]        
        public DateTime? StartTime { get; set; }
        
        /// <summary>
        /// 有效时长，截止
        /// </summary>
        [SugarColumn(ColumnName = "EndTime")]        
        public DateTime? EndTime { get; set; }
        
        /// <summary>
        /// 排序码
        /// </summary>
        [SugarColumn(ColumnName = "SortCode")]        
        public long? SortCode { get; set; }
        
        /// <summary>
        /// 创建用户
        /// </summary>
        [SugarColumn(ColumnName = "CreatorUserId")]        
        public string CreatorUserId { get; set; }
        
        /// <summary>
        /// 创建用户姓名
        /// </summary>
        [SugarColumn(ColumnName = "CreatorUserName")]        
        public string CreatorUserName { get; set; }
        
        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(ColumnName = "CreatorTime")]        
        public DateTime? CreatorTime { get; set; }
        
        /// <summary>
        /// 所在区域Id
        /// </summary>
        [SugarColumn(ColumnName = "doorAreaId")]        
        public string DoorAreaId { get; set; }
        
        /// <summary>
        /// 所在区域名称
        /// </summary>
        [SugarColumn(ColumnName = "doorAreaName")]        
        public string DoorAreaName { get; set; }
        
        /// <summary>
        /// 门禁位置
        /// </summary>
        [SugarColumn(ColumnName = "ctlposition")]        
        public string Ctlposition { get; set; }
        
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "dbDate")]        
        public DateTime? DbDate { get; set; }
        /// <summary>
        /// 删除标志
        /// </summary>
        [SugarColumn(ColumnName = "F_DeleteMark")]
        public int? DeleteMark { get; set; }

        /// <summary>
        /// 删除时间
        /// </summary>
        [SugarColumn(ColumnName = "F_DeleteTime")]
        public DateTime? DeleteTime { get; set; }

        /// <summary>
        /// 删除用户
        /// </summary>
        [SugarColumn(ColumnName = "F_DeleteUserId")]
        public string DeleteUserId { get; set; }

        /// <summary>
        /// 删除用户
        /// </summary>
        [SugarColumn(ColumnName = "F_DeleteUserName")]
        public string DeleteUserName { get; set; }

        /// <summary>
        /// 所属公司Id
        /// </summary>
        [SugarColumn(ColumnName = "CompanyId")]
        public string CompanyId { get; set; }

        /// <summary>
        /// 公司名称
        /// </summary>
        [SugarColumn(ColumnName = "CompanyName")]
        public string CompanyName { get; set; }
        /// <summary>
        /// 权限状态 1启用 0禁用
        /// </summary>
        [SugarColumn(ColumnName = "AuthStatus")]
        public int AuthStatus { get; set; }

        /// <summary>
        /// 创建
        /// </summary>
        public virtual void Create()
        {
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.Id = YitIdHelper.NextId().ToString();
            this.CreatorTime = DateTime.Now;
            this.DeleteMark = 0;
            if (!string.IsNullOrEmpty(userId))
            {
                this.CreatorUserId = CreatorUserId == null ? userId : CreatorUserId;
                this.CreatorUserName = CreatorUserName == null ? userName : CreatorUserName;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        public virtual void Delete()
        {
            this.DeleteMark = 1;
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.DeleteTime = DateTime.Now;
            if (!string.IsNullOrEmpty(userId))
            {
                this.DeleteUserId = userId;
                this.DeleteUserName = userName;
            }
        }

    }
}